package main

import (
	"config"
	"fmt"
)

type listenDefined struct {
}

func (lsd listenDefined) Listen(oldConf *config.Configuration, newConf *config.Configuration) bool {
	if newConf == nil {
		return false
	}
	section, _ := newConf.GetSection("default")
	kvNode, _ := section.GetKvNode("name")
	if kvNode.Val() == "guokaijie" {
		return true
	}
	return false
}

func main() {
	filename := "example.conf"
	var lsd listenDefined
	conf, err := config.WatcherRoutine(filename, lsd)
	if err != nil {
		fmt.Println(err)
	}
	// 获取已知的信息
	for _, section := range conf.Sections() {
		fmt.Println("section:", section.Name())
		for _, kvNode := range section.KvNodes() {
			fmt.Printf("--'%s' is '%s'\n", kvNode.Key(), kvNode.Val())
		}
	}
}
